package pers.qianyu.controller;

import lombok.extern.slf4j.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.domain.*;
import pers.qianyu.service.*;
import pers.qianyu.service.impl.*;

@Slf4j
@RestController
public class OrderController2 {
    @Autowired
    private ProductService productService;
    @Autowired
    private OrderServiceImpl2 orderServiceImpl2;

    @GetMapping("/order/product/tx/{pid}")
    public Order order(@PathVariable Integer pid) {
        log.info("收到{}号商品的下单请求，接下来调用订单微服务查询订单", pid);
        Product product = productService.findById(pid);
        log.info("查询到商品号{}的商品信息：{}", pid, product.toString());

        Order order = new Order();
        order.setUid(1);
        order.setUsername("小雨");
        order.setPid(pid);
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        order.setNumber(1);
        orderServiceImpl2.createOrderBefore(order);
        log.info("新建订单：{}", order.toString());

        return order;
    }
}
